package controller;

import java.util.ArrayList;

import model.CustomerContainer;
import model.Customer;
	
public class CustomerController {

	private static CustomerController customerController = null;
	private static CustomerContainer customerContainer; 
	/** Making the class private as per the singleton pattern */
	private CustomerController(){
		customerContainer = CustomerContainer.getInstance();
	}
	/** Creating an instance of the class*/
	public static CustomerController getInstance(){
		if(customerController == null){
			customerController = new CustomerController();
		}
		return customerController;
	}
	
	public String getName(int id){
		return customerContainer.findCustomer(id).getName();
	}
	
	public void setName(int id, String name){
		customerContainer.findCustomer(id).setName(name);
	}

	public String getAdress(int id){
		return customerContainer.findCustomer(id).getAdress();
	}
	
	public void setAdress(int id, String adress){
		customerContainer.findCustomer(id).setName(adress);
	}

	public int getPostalCode(int id){
		return customerContainer.findCustomer(id).getPostalCode();
	}
	
	public void setName(int id, int postalCode){
		customerContainer.findCustomer(id).setPostalCode(postalCode);
	}

	public String getCity(int id){
		return customerContainer.findCustomer(id).getCity();
	}
	
	public void setCity(int id, String city){
		customerContainer.findCustomer(id).setName(city);
	}
	
	public int getPhone(int id){
		return customerContainer.findCustomer(id).getPhone();
	}
	
	public void setPhone(int id, int phone){
		customerContainer.findCustomer(id).setPhone(phone);
	}

	public String getEmail(int id){
		return customerContainer.findCustomer(id).getEmail();
	}
	
	public void setEmail(int id, String email){
		customerContainer.findCustomer(id).setEmail(email);
	}
		
	public double getDiscount(int id) {
		return customerContainer.findCustomer(id).getDiscount();
	}
	
	public void setDiscount(int id, double discount) {
		customerContainer.findCustomer(id).setDiscount(discount);
	}
		
	
	/** Calling the addCustomer in the customerContainer that contains
	 * an instance of the singleton class of CustomerContainer in the model layer.  */
	public void createCustomer(String name, String adress, int postalCode, String city, int phone, String email, double discount){
		customerContainer.addCustomer(new Customer(name, adress, postalCode, city, phone, email, discount));
	}
	/** Updating the customer by calling the model layer methods in CustomerContainer*/
	public void updateCustomer(String name, String adress, int postalCode, String city, int phone, String email, double discount){
		Customer customer = customerContainer.findCustomer(phone);
		customer.setName(name);
		customer.setAdress(adress);
		customer.setPostalCode(postalCode);
		customer.setCity(city);
		customer.setPhone(phone);
		customer.setEmail(email);
		customer.setDiscount(discount);
	}
	/** Returns an array list of orders in String format through the OrderController in the controller layer */
	public ArrayList<String> getCustomerOrders(int id){
		return OrderController.getInstance().getOrders(id);
	}
	
	public void removeCustomer(int customerId){
		customerContainer.removeCustomer(customerContainer.findCustomer(customerId));
	}
}
